﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * 目标标本：4.0.30319.239
 * 
 * 最后修改：2011/11/22 17:37:38
 * ************************************************************/
namespace Mozlite.Common
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Data;
    using System.Collections.Generic;
    using Mozlite.Common.Configuration;

    /// <summary>
    /// 导航实例。
    /// </summary>
    public class Navigator : BaseObject
    {
        /// <summary>
        /// 初始化类<see cref="T:Mozlite.Common.Navigator"/>。
        /// </summary>
        public Navigator() { }

        /// <summary>
        /// 初始化类<see cref="T:Mozlite.Common.Navigator"/>。
        /// </summary>
        /// <param name="key">模板唯一键。</param>
        public Navigator(string key)
        {
            var theme = ThemeConfiguration.Themes[key];
            if (theme != null)
                this.ThemeID = theme.GuidKey;
        }

        /// <summary>
        /// 模板唯一键。
        /// </summary>
        public Guid ThemeID { get; set; }

        /// <summary>
        /// 网站设置ID。
        /// </summary>
        public int SettingsID { get; set; }

        /// <summary>
        /// 导航ID。
        /// </summary>
        public int NavigatorID { get; set; }

        /// <summary>
        /// 导航名称。
        /// </summary>
        public string DisplayName { get; set; }

        /// <summary>
        /// 唯一键。
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 获取或设置英文名称。
        /// </summary>
        public string EnglishName { get; set; }

        /// <summary>
        /// 父导航ID。
        /// </summary>
        public int ParentID { get; set; }

        /// <summary>
        /// 排序。
        /// </summary>
        public int SortOrder { get; set; }

        /// <summary>
        /// 导航URL地址。
        /// </summary>
        public string NavigatorUrl { get; set; }

        /// <summary>
        /// 点击事件。
        /// </summary>
        public string OnClick { get; set; }

        /// <summary>
        /// 标题。
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 获取或设置样式。
        /// </summary>
        public string Style { get; set; }

        /// <summary>
        /// 导航位置。
        /// </summary>
        public NavigatorLocation Location { get; set; }

        /// <summary>
        /// 从数据库中加载数据。
        /// </summary>
        /// <param name="reader">数据库读取器。</param>
        protected override void Load(IDataReader reader)
        {
            this.ThemeID = reader.GetGuid("ThemeID");
            this.SettingsID = reader.GetInt32("SettingsID");
            this.NavigatorID = reader.GetInt32("NavigatorID");
            this.DisplayName = reader.GetString("DisplayName");
            this.EnglishName = reader.GetString("EnglishName");
            this.ParentID = reader.GetInt32("ParentID");
            this.SortOrder = reader.GetInt32("SortOrder");
            this.NavigatorUrl = reader.GetString("NavigatorUrl");
            this.OnClick = reader.GetString("OnClick");
            this.Title = reader.GetString("Title");
            this.Style = reader.GetString("Style");
            this.Key = reader.GetString("Key");
            this.Location = reader.TGet<NavigatorLocation>("Location");
        }

        private Navigator parent;
        /// <summary>
        /// 父导航实例对象。
        /// </summary>
        public Navigator Parent
        {
            get
            {
                if (parent == null)
                    parent = Navigators.GetParent(this);
                return parent;
            }
        }

        private List<Navigator> children;
        /// <summary>
        /// 获取子导航列表。
        /// </summary>
        public List<Navigator> Children {
            get {
                if (children == null)
                    children = Navigators.GetChildren(this);
                return children;
            }
        }
    }
}